package com.jackfangqi.zhihuijizhou.activities;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;

import com.jackfangqi.zhihuijizhou.R;
import com.jackfangqi.zhihuijizhou.adapters.TutorialAdapter;
import com.jackfangqi.zhihuijizhou.constants.Constant;

import java.util.ArrayList;
import java.util.List;

public class TutorialActivity extends Activity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_tutorial);

        PackageManager packageManager = getPackageManager();
        int versionCode = 1;
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
            versionCode = packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        SharedPreferences sharedPreferences = getSharedPreferences(Constant.SP_NAME_APP, MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(Constant.IS_SHOWN + versionCode, true);
        editor.apply();

        ViewPager pager = (ViewPager) findViewById(R.id.tutorial_pager);
        List<Integer> imgs = new ArrayList<>();
        imgs.add(R.mipmap.help1);
        imgs.add(R.mipmap.help2);
        imgs.add(R.mipmap.help3);
        imgs.add(R.mipmap.help4);

        TutorialAdapter adapter = new TutorialAdapter(this, imgs);
        adapter.setOnClickListener(this);
        pager.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.login:
                // TODO 登陆
                break;
            case R.id.create_new:
                // TODO 注册
                break;
            case R.id.go:
                startActivity(new Intent(this, MainActivity.class));
                this.finish();
                break;
        }
    }
}
